import 'package:convex_bottom_bar/convex_bottom_bar.dart';
import 'package:flutter/material.dart';
import 'package:sites_hub/pages/keyboard_page.dart';
import 'package:sites_hub/pages/note_page.dart';
import 'package:sites_hub/pages/site_page.dart';

class NavigationPageItem {
  String pageName;
  Widget page;
  TabItem navigationItem;

  NavigationPageItem(
      {required this.pageName,
      required this.page,
      required this.navigationItem});
}

class PageManager {
  static final List<NavigationPageItem> _list = [
    NavigationPageItem(
        pageName: 'site_page',
        page: SitePage(),
        navigationItem: TabItem(icon: Icons.home, title: 'Home')),
    NavigationPageItem(
        pageName: 'note_page',
        page: NotePage(),
        navigationItem: TabItem(icon: Icons.map, title: 'Discovery')),
    NavigationPageItem(
        pageName: 'keyboard_page',
        page: KeyboardPage(),
        navigationItem: TabItem(icon: Icons.add, title: 'Add'))
  ];

  static List<NavigationPageItem> get list => _list;

  static final Map<String, NavigationPageItem> _pageContainer = {
    for (var it in _list) it.pageName: it
  };

  static List<TabItem> items() {
    return _list.map((it) => it.navigationItem).toList();
  }

  static Widget go(String path) {
    var result = _pageContainer[path];
    if (result == null) {
      return const Center(
        child: Text('page not found'),
      );
    }
    return result.page;
  }
}
